// utils/component/sweetsAnimation/sweetsAnimation.js
const comm = require('../../../utils/common.js');

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    innerData: {
      type: Object,
      value: {},
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    flag: true,
    isClick: false,
    showAward: true,
    getSweets: "getSweets",
    screenHeight: comm.screenHeight,
    screenWidth: comm.screenWidth,
    hide: "hide"
  },
  /**
   * 组件的方法列表
   */
  methods: {

    getSweets: function (e) {
      this.setData({
        getSweets: "disableGetSweets"
      })
      this.animationJar = wx.createAnimation({
        duration: 30,
        timingFunction: 'ease',
      })
      this.animationCap = wx.createAnimation({
        duration: 30,
        timingFunction: 'ease',
        delay: 1530
      })
      this.animationLight = wx.createAnimation({
        duration: 30,
        timingFunction: 'ease',
        delay: 1530
      })
      
      this.animationAward = wx.createAnimation({
        duration: 30,
        timingFunction: 'ease',
        delay: 1000
      })
      let transHeight = this.data.screenHeight*0.3
      this.animationJar.rotate(10).step();
      this.animationJar.rotate(-10).step();
      this.animationJar.rotate(10).step();
      this.animationJar.rotate(-10).step();
      this.animationJar.rotate(0).step();
      this.animationJar.scale(2, 2).step({ duration: 500 });
      this.animationJar.translate(0, transHeight).step({ duration: 500 })
      this.animationCap.rotate(90).translate(100, -800).step({ duration: 2000 })
      this.animationLight.opacity(1).step({ duration: 500});   

      this.animationAward.scale(0.1, 0.1).step();
      this.animationAward.opacity(1).scale(1, 1).step({ duration: 300 });
   

      this.setData({
        animationJar: this.animationJar.export(),
        animationCap: this.animationCap.export(),
        animationLight: this.animationLight.export(),
        showAward: false,
        animationAward: this.animationAward.export(),
      })

      // this.setData({ flag: true })
    },

    getAward: function(e){
      
    },

    disableGetSweets: function(e){
      this.setData({ flag: true })
    },
    // 关闭弹窗
    closeView: function (e) {
      console.log("点击了关闭！")
    },
    // 显示
    show: function () {
      this.setData({ flag: false })
      this.getSweets()
    },
    // 隐藏
    hide: function (e) {

      // 动画全部复位
      this.animationJar = wx.createAnimation({})
      this.animationCap = wx.createAnimation({})
      this.animationAward = wx.createAnimation({})
      this.animationLight = wx.createAnimation({})
      this.animationAward.scale(0, 0).opacity(0).scale(1, 1).step();
      this.animationJar.rotate(0).translate(0, 0).step();
      this.animationLight.opacity(0).step();   
      this.animationCap.rotate(0).translate(0, 0).step()
      this.setData({
        animationJar: this.animationJar.export(),
        animationCap: this.animationCap.export(),
        animationLight: this.animationLight.export(),
        animationAward: this.animationAward.export(),
      })

      this.setData({ flag: true })
    }
  }
})
